package com.aleaho.cftrack.model;

import com.aleaho.cftrack.CFTrackApplication;
import com.aleaho.cftrack.utils.TrackConsts;
import com.baidu.trace.api.entity.EntityListRequest;
import com.baidu.trace.api.entity.FilterCondition;
import com.baidu.trace.api.entity.OnEntityListener;
import com.baidu.trace.api.track.LatestPointRequest;
import com.baidu.trace.api.track.OnTrackListener;
import com.baidu.trace.model.ProcessOption;

import java.util.List;

/**
 * @author Aleaho
 * @version 1.0
 * @date 2017/11/2
 * @desc
 */

public class LocationModelImpl implements LocationModel {

    private EntityListRequest entityListRequest = new EntityListRequest();
    private LatestPointRequest latestPointRequest = new LatestPointRequest();
    @Override
    public void queryEntityList(CFTrackApplication trackApp, List<String> entities, long activeTime, int pageIndex,  OnEntityListener onEntityListener) {

        trackApp.initRequest(entityListRequest);
        FilterCondition filterCondition = new FilterCondition();

        //查找当前10分钟之内有定位信息上传的entity
        filterCondition.setActiveTime(activeTime);
        filterCondition.setEntityNames(entities);
        entityListRequest.setFilterCondition(filterCondition);
        entityListRequest.setPageIndex(pageIndex);
        entityListRequest.setPageSize(TrackConsts.ENTITY_PAGE_SIZE);

        trackApp.mClient.queryEntityList(entityListRequest, onEntityListener);


    }

    @Override
    public void queryLatestPoint(CFTrackApplication trackApp, String entity,OnTrackListener onTrackListener) {
        trackApp.initRequest(latestPointRequest);

        latestPointRequest.setEntityName(entity);
        ProcessOption processOption = new ProcessOption();
        processOption.setNeedDenoise(true);
        processOption.setRadiusThreshold(100);
        latestPointRequest.setProcessOption(processOption);
        trackApp.mClient.queryLatestPoint(latestPointRequest, onTrackListener);

    }
}
